package STUDENT.TRINHQUANGXUANDUC.OPPS.QuanLyNhanSu.Views;

import java.awt.EventQueue;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.border.EmptyBorder;

import STUDENT.TRINHQUANGXUANDUC.OPPS.QuanLyNhanSu.Controllers.Controllers;
import STUDENT.TRINHQUANGXUANDUC.OPPS.QuanLyNhanSu.Entry.Nhanvien;

public class ViewNhanvien extends JFrame {

	private JPanel contentPane;
	private JTextField txtmanhanvien;
	private JTextField txttennhanvien;
	private JTextField txtdiachi;
	private JTextField txtsdt;
	private JTextField txtbacluong;
	private JTextArea taNhanvien;
	Nhanvien objNhanvien;
	Controllers Controller = new Controllers();

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					ViewNhanvien frame = new ViewNhanvien();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public ViewNhanvien() {
		Controller.loaddata();
		setTitle("Quan li nhan vien");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 586, 403);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);

		JLabel lblMaNhanVien = new JLabel("Ma nhan vien");

		JLabel lblTenNhanVien = new JLabel("Ten nhan vien");

		JLabel lblDiaChi = new JLabel("Dia chi");

		JLabel lblSoDienThoai = new JLabel("So dien thoai");

		JLabel lblBacLuong = new JLabel("Bac luong");

		txtmanhanvien = new JTextField();
		txtmanhanvien.setColumns(10);

		txttennhanvien = new JTextField();
		txttennhanvien.setColumns(10);

		txtdiachi = new JTextField();
		txtdiachi.setColumns(10);

		txtsdt = new JTextField();
		txtsdt.setColumns(10);

		txtbacluong = new JTextField();
		txtbacluong.setColumns(10);
		taNhanvien = new JTextArea();
		taNhanvien.setColumns(5);
		taNhanvien.setRows(3);

		taNhanvien.setText(loadDataNhanVien());

		JButton btnThem = new JButton("Them");
		btnThem.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent arg0) {
				objNhanvien = new Nhanvien();
				objNhanvien.setHoten(txttennhanvien.getText());
				objNhanvien.setIdnhanvien(Integer.parseInt(txtmanhanvien.getText()));
				objNhanvien.setSodienthoai(Integer.parseInt(txtsdt.getText()));
				objNhanvien.setDiachi(txtdiachi.getText());
				objNhanvien.setBacluong(Integer.parseInt(txtbacluong.getText()));
				Controller.addNhanvien(objNhanvien);
				taNhanvien.setText(loadDataNhanVien());
			}
		});

		JLabel lblDanhSachNhan = new JLabel("Danh sach nhan vien");

		JScrollPane scrNhanvien = new JScrollPane(taNhanvien);
		GroupLayout gl_contentPane = new GroupLayout(contentPane);
		gl_contentPane.setHorizontalGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING)
				.addGroup(gl_contentPane.createSequentialGroup()
						.addComponent(scrNhanvien, GroupLayout.DEFAULT_SIZE, 530, Short.MAX_VALUE).addGap(2))
				.addGroup(gl_contentPane.createSequentialGroup().addComponent(lblDanhSachNhan).addGap(432))
				.addGroup(gl_contentPane.createSequentialGroup().addGap(15)
						.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
								.addComponent(lblMaNhanVien).addComponent(lblTenNhanVien).addComponent(lblDiaChi)
								.addComponent(lblSoDienThoai).addComponent(lblBacLuong))
						.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING).addComponent(btnThem)
								.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
										.addComponent(txtbacluong, Alignment.TRAILING)
										.addComponent(txtsdt, Alignment.TRAILING)
										.addComponent(txtdiachi, Alignment.TRAILING)
										.addComponent(txttennhanvien, Alignment.TRAILING).addComponent(txtmanhanvien,
												Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, 447, Short.MAX_VALUE)))
						.addGap(2)));
		gl_contentPane.setVerticalGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_contentPane.createSequentialGroup()
						.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
								.addGroup(gl_contentPane.createSequentialGroup().addGap(3).addComponent(lblMaNhanVien))
								.addComponent(txtmanhanvien,
										GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
										GroupLayout.PREFERRED_SIZE))
						.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
								.addGroup(gl_contentPane.createSequentialGroup().addGap(9).addComponent(lblTenNhanVien))
								.addGroup(gl_contentPane.createSequentialGroup()
										.addPreferredGap(ComponentPlacement.RELATED).addComponent(txttennhanvien,
												GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
												GroupLayout.PREFERRED_SIZE)))
						.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
								.addGroup(gl_contentPane.createSequentialGroup().addGap(9).addComponent(lblDiaChi))
								.addGroup(gl_contentPane.createSequentialGroup()
										.addPreferredGap(ComponentPlacement.RELATED).addComponent(
												txtdiachi, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
												GroupLayout.PREFERRED_SIZE)))
						.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
								.addGroup(gl_contentPane.createSequentialGroup().addGap(9)
										.addComponent(lblSoDienThoai))
								.addGroup(gl_contentPane.createSequentialGroup()
										.addPreferredGap(ComponentPlacement.RELATED).addComponent(txtsdt,
												GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
												GroupLayout.PREFERRED_SIZE)))
						.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
								.addGroup(gl_contentPane.createSequentialGroup().addGap(9).addComponent(lblBacLuong))
								.addGroup(gl_contentPane.createSequentialGroup()
										.addPreferredGap(ComponentPlacement.RELATED).addComponent(txtbacluong,
												GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
												GroupLayout.PREFERRED_SIZE)))
						.addPreferredGap(ComponentPlacement.RELATED).addComponent(btnThem).addGap(14)
						.addComponent(lblDanhSachNhan).addPreferredGap(ComponentPlacement.RELATED)
						.addComponent(scrNhanvien, GroupLayout.DEFAULT_SIZE, 156, Short.MAX_VALUE).addContainerGap()));
		contentPane.setLayout(gl_contentPane);
	}

	private String loadDataNhanVien() {
		return Controller.getListNhanviens();
	}
}
